#!/bin/bash
#
# "ldconfig" wrapper for scratchbox 2:
# ldconfig is a statically linked binary.
#
# Copyright (c) 2008 Nokia Corporation.
# All rights reserved.
# Author: Lauri T. Aarnio
#
# Licensed under GPL version 2

args="$*"
prog="$0"
progbase=`basename $0`

function error_not_inside_sb2()
{
	echo "SB2: $progbase wrapper: This wrapper can only be used from inside"
	echo "the scratchbox 2'ed environment"
	exit 1
}

if [ -z "$SBOX_SESSION_DIR" ]
then
	error_not_inside_sb2
fi

. $SBOX_SESSION_DIR/sb2-session.conf

if [ -z "$sbox_mapmode" -o -z "$sbox_dir" ]
then
	error_not_inside_sb2
fi

sbox_ldconfig_path=""
sbox_ldconfig_root=""
# read-in mode-specific settings
if [ -f $SBOX_SESSION_DIR/modes/$sbox_mapmode/sb2rc ]
then
	. $SBOX_SESSION_DIR/modes/$sbox_mapmode/sb2rc "$progbase"
fi

if [ -z "$sbox_ldconfig_path" ]
then
	sbox_ldconfig_path="$sbox_target_root/sbin/ldconfig"
fi
if [ -z "$sbox_ldconfig_root" ]
then
	sbox_ldconfig_root="$sbox_target_root"
fi

export SBOX_ALLOW_STATIC_BINARY=$sbox_ldconfig_path
exec $sbox_ldconfig_path -r "$sbox_ldconfig_root" $args
